use std::io;

const MN: usize = 400500;

static mut T: [i64; MN] = [0i64; MN];
static mut G: [i64; MN] = [0i64; MN];

fn init(t: &mut [i64; MN], arr: &Vec<i64>, l: usize, r: usize, p: usize) {
  if l == r {
    t[p] = arr[l];
    return;
  }
  let mid = (l + r) / 2;
  init(t, arr, l, mid, p << 1);
  init(t, arr, mid + 1, r, p << 1 | 1);
  t[p] = t[p << 1] + t[p << 1 | 1];
}

fn psd(t: &mut [i64; MN], g: &mut [i64; MN], l: i32, r: i32, p: usize) {
  if g[p] != 0 {
    let mid: i32 = (l + r) / 2;
    t[p << 1] += g[p] * ((mid - l + 1) as i64);
    t[p << 1 | 1] += g[p] * ((r - mid) as i64);
    g[p << 1] += g[p];
    g[p << 1 | 1] += g[p];
    g[p] = 0;
  }
}

fn mdf(
  t: &mut [i64; MN],
  g: &mut [i64; MN],
  p: usize,
  l: usize,
  r: usize,
  ml: usize,
  mr: usize,
  mk: i64,
) {
  if l >= ml && r <= mr {
    t[p] += ((r - l + 1) as i64) * mk;
    g[p] += mk;
    return;
  }
  psd(t, g, l as i32, r as i32, p);
  let mid = (l + r) / 2;
  if ml <= mid {
    mdf(t, g, p << 1, l, mid, ml, mr, mk);
  }
  if mr > mid {
    mdf(t, g, p << 1 | 1, mid + 1, r, ml, mr, mk);
  }
  t[p] = t[p << 1] + t[p << 1 | 1];
}

fn qry(
  t: &mut [i64; MN],
  g: &mut [i64; MN],
  p: usize,
  l: usize,
  r: usize,
  ql: usize,
  qr: usize,
) -> i64 {
  if l >= ql && r <= qr {
    t[p]
  } else {
    psd(t, g, l as i32, r as i32, p);
    let mut ret = 0i64;
    let mid = (l + r) / 2;
    if ql <= mid {
      ret += qry(t, g, p << 1, l, mid, ql, qr);
    }
    if qr > mid {
      ret += qry(t, g, p << 1 | 1, mid + 1, r, ql, qr);
    }
    ret
  }
}

fn main() {
  let mut line: String = String::new();

  io::stdin().read_line(&mut line).unwrap();
  let mut s = line.trim().split(' ');
  let n: i32 = s.next().unwrap().parse().unwrap();
  let m: i32 = s.next().unwrap().parse().unwrap();

  line = String::new();
  io::stdin().read_line(&mut line).unwrap();
  s = line.trim().split(' ');
  let mut arr: Vec<i64> = Vec::from([0]);
  for i in s {
    arr.push(i.parse().unwrap());
  }
  unsafe {
    init(&mut T, &arr, 1, n as usize, 1);
  }

  for i in 1..=m {
    line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    s = line.trim().split(' ');
    let o: i32 = s.next().unwrap().parse().unwrap();
    let x: i32 = s.next().unwrap().parse().unwrap();
    let y: i32 = s.next().unwrap().parse().unwrap();
    if o == 2 {
      unsafe {
        println!(
          "{}",
          qry(&mut T, &mut G, 1, 1, n as usize, x as usize, y as usize)
        );
      }
    } else {
      let k: i64 = s.next().unwrap().parse().unwrap();
      unsafe {
        mdf(&mut T, &mut G, 1, 1, n as usize, x as usize, y as usize, k);
      }
    }
  }
}
